package com.ymatou.iapi.csim.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.LoginBean;
import com.ymatou.iapi.csim.service.LoginCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_onlinecs;
import com.ymttest.database.sqlwapper.CSIM.ymt_cssessionWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
/**
*客服登录
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_Login{
	private static LoginBean bean;
	private static LoginCall call;
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	private Integer sellerId1=Integer.parseInt(EnvSetup.getData("autotest_seller1").toString());
	private static ymt_onlinecsWapper onlinecsWapper=new ymt_onlinecsWapper();

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("客服登录");
	}

	@Before
	public void caseUp() throws InterruptedException {
		bean=new LoginBean();
		call=new LoginCall();

	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Login_001() {
		Logger.start(true,"客服登录-买家客服，当前客服不在线，返回正常登录");
		try {
			onlinecsWapper.deleteBy(MapUtil.hashMap("csId",csId));
			
			bean.setCsId(csId);
			bean.setCsName("买家客服1");
			bean.setCsNickName("买家昵称1");
			bean.setCsType(0);
			bean.setSocketIoToken("1111");
			bean.setAreaName("CN");
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("0",call.getResult().get("ErrorCode").toString(), "验证返回的errorCode");
			Logger.verifyEquals("",call.getResult().get("ErrorMessage"), "验证返回的errorMessage");
			Logger.verifyEquals(true,call.getResult().get("Success"), "验证返回的Success");
			Logger.verifyEquals("200",call.getStatus(), "验证返回的status");
			//验证数据库
			ymt_onlinecs onlinecs=onlinecsWapper.selectBy(MapUtil.hashMap("CSId",csId)).get(0);
			Logger.verifyEquals(onlinecs.getCSId(),bean.getCsId(), "验证数据库中的CsId");
			Logger.verifyEquals(1,onlinecs.getStatus(), "验证数据库中的Status");
			Logger.verifyEquals(bean.getCsName(),onlinecs.getCSName(), "验证数据库中的CSName");
			Logger.verifyEquals(bean.getCsType(),onlinecs.getCSType(), "验证数据库中的CsType");
			Logger.verifyEquals(bean.getAreaName(),onlinecs.getArea(), "验证数据库中的Area");
			Logger.verifyEquals(bean.getCsNickName(),onlinecs.getCSNickName(), "验证数据库中的CSNickName");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Login_002() {
		Logger.start(true,"客服登录-买手客服，当前客服不在线，返回正常登录");
		try {
			onlinecsWapper.deleteBy(MapUtil.hashMap("csId",sellerId1));
			bean.setCsId(sellerId1);
			bean.setCsName("买手客服1");
			bean.setCsNickName("买手昵称1");
			bean.setCsType(1);
			bean.setSocketIoToken("1111");
			bean.setAreaName("CN");
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("0",call.getResult().get("ErrorCode").toString(), "验证返回的errorCode");
			Logger.verifyEquals("",call.getResult().get("ErrorMessage"), "验证返回的errorMessage");
			Logger.verifyEquals(true,call.getResult().get("Success"), "验证返回的Success");
			Logger.verifyEquals("200",call.getStatus(), "验证返回的status");
			//验证数据库
			ymt_onlinecs onlinecs=onlinecsWapper.selectBy(MapUtil.hashMap("CSId",bean.getCsId())).get(0);
			Logger.verifyEquals(onlinecs.getCSId(),bean.getCsId(), "验证数据库中的CsId");
			Logger.verifyEquals(1,onlinecs.getStatus(), "验证数据库中的Status");
			Logger.verifyEquals(bean.getCsName(),onlinecs.getCSName(), "验证数据库中的CSName");
			Logger.verifyEquals(bean.getCsType(),onlinecs.getCSType(), "验证数据库中的CsType");
			Logger.verifyEquals(bean.getAreaName(),onlinecs.getArea(), "验证数据库中的Area");
			Logger.verifyEquals(bean.getCsNickName(),onlinecs.getCSNickName(), "验证数据库中的CSNickName");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Login_003() {
		Logger.start(true,"客服登录-当前客服在线，返回登录失败");
		try {
			int count1=onlinecsWapper.selectBy_Count(MapUtil.hashMap("CSId",csId));
			bean.setCsId(csId);
			bean.setCsName("买家客服1");
			bean.setCsNickName("买家昵称1");
			bean.setCsType(0);
			bean.setSocketIoToken("1111");
			bean.setAreaName("CN");
			call.setData(bean);
			call.callService();
			call.callService();		
			int count2=onlinecsWapper.selectBy_Count(MapUtil.hashMap("CSId",csId));
			Logger.verifyEquals(0, count2-count1, "验证数据库没有增加在线客服");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}